import 'package:flutter/material.dart';
import '../model/DuZheLunModel.dart';
import 'dart:convert';

class CommentPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return CommentState();
  }
}

class CommentState extends State<CommentPage> {
  List<dynamic> list = [];

  @override
  void initState() {
    super.initState();
    loadData();
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: list.length,
        itemBuilder: (context, index) {
          return Column(
            children: <Widget>[
              Divider(
                height: 1,
                color: Color(0xffCBCACA),
              ),
              Container(
                padding: EdgeInsets.only(left: 10, right: 10, top: 10),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    ClipOval(
                      child: Image.network(
                        (list[index] as Datas).avatar,
                        width: 30,
                        height: 30,
                      ),
                    ),
                    Expanded(
                        child: Padding(
                            padding: EdgeInsets.only(left: 10),
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.start,
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                SizedBox(
                                    height: 30,
                                    child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: <Widget>[
                                        Expanded(
                                          child: Text(
                                            (list[index] as Datas).nickname,
                                            style: TextStyle(
                                                fontSize: 13,
                                                color: Color(0xff666666)),
                                          ),
                                        ),
                                        Text(
                                          (list[index] as Datas).updateTime,
                                          textAlign: TextAlign.end,
                                          style: TextStyle(
                                              fontSize: 10,
                                              color: Color(0xffD0D0D0)),
                                        )
                                      ],
                                    )),
                                Padding(
                                  padding: EdgeInsets.only(top: 5, bottom: 8),
                                  child: Text(
                                    (list[index] as Datas).content,
                                    style: TextStyle(
                                        fontSize: 15, color: Color(0xff454545)),
                                  ),
                                ),
                                Container(
                                  height: 1, color: Color(0xffe7e7e7)
                                ),
                                SizedBox(
                                    height: 50,
                                    child: Row(
                                      children: <Widget>[
                                        Expanded(
                                          child: Text(
                                            (list[index] as Datas).title,
                                            style: TextStyle(
                                                fontSize: 18,
                                                color: Color(0xff7A7A7A)),
                                          ),
                                        ),
                                        Image.asset(
                                            "image/indiimg_9x17_@2x.png",
                                            width: 18,
                                            height: 18)
                                      ],
                                    )),
                              ],
                            )))
                  ],
                ),
              ),
              Divider(
                height: 1,
                color: Color(0xffCBCACA),
              ),
              Container(
                color: Color(0xffF8F7F5),
                height: 10,
              )
            ],
          );
        });
  }

  void loadData() async {
    String str = await DefaultAssetBundle.of(context)
        .loadString("json/DuzhelunData.json");
    DuZheLunModel model = DuZheLunModel.fromJson(json.decode(str));
    setState(() {
      list = model.datas;
      print("size：${(list[0] as Datas).nickname}");
    });
  }
}
